<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : EasyPayService.php
 * Created on : 2022-12-30 14:07:46
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace haoteam\service;

use Yansongda\Pay\Pay;
use Yansongda\Pay\Log;
use app\admin\model\AdminConfig;

/**
 * 
 * https://pay.yansongda.cn/docs/v2/quickUsage.html
 * Class EasyPayService
 * Tiger <1192851302@qq.com> 2022-12-30 14:07:46
 */
class EasyPayService {

    protected static $config = [
        'log' => [// optional
            'file' => './logs/alipay.log',
            'level' => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效，默认 30 天
        ],
        'http' => [// optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
        // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ]
    ];

    /**
     * 支付宝支付
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public static function alipay() {
        $options = AdminConfig::getMore(['system_alipay_appid', 'system_alipay_public_key', 'system_alipay_private_key']);
        self::$config = array_merge(self::$config, [//2021001198616656
            'app_id' => $options['system_alipay_appid'] ?? '2021001198616656',
            'notify_url' => request()->domain() . '/api/easypay/alipay/payment',
            'ali_public_key' => $options['system_alipay_public_key'] ?? 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsvSVgFMp246CbdNXBuevPU6U66ZHgX4Yc1UPUGw3GC0QUbRg9Kbti3493izJI4q9dpyR0GmS7WbdJX1s49XPLaBcyoxLAoAr+uddloEIHXQpv2hypFkWztN2QVmzn4bja6h+LXfYy7NNpcWvy0wP4r5W1xdZUPakkFaXqHFzaKe/4jUs64LVdT4wpHPP+mWtJGyydPY1mbo2SINn279KLgAdoZjIIkJXN0eOkUYxle8PqyUgZfGOFBifpSI/BrfPdju8RGz6RrC1z5PXwn/w7ge36lpSG1BsP91f7ItrdrnlqBLTLFYRM2hpFMNzIk7iC29kN2xBPLFppn7aGnr8JwIDAQAB',
            'private_key' => $options['system_alipay_private_key'] ?? 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCMURmNetjeZP2oBwAdq1h0SSHX3lQ4z17fYKD5lEOvSt85MrJAZ1YCcsIH7N11H6bdg8dU5Tn/ZD9cfcEid8oU0s90DKQLq5tVSXJi0tsomPOVw2Q5wwFhX9AzuJ9gQL4zLc/fdS6yK46a7Yk5RZcAiQjDkBy7Th+Otyyha22ykJTwCxTXYLL+46Pd9MLDZMc5jmL8yg4+WI0tTfUXLPbefytAVxxF1ttRvLB/lh9qtR+rtzXY7DL+hFw7auURPpOeThtF3tpU+1QzpKAIprqvrotRcOh5nD5VYZjbzRU54lLpjmz1GVhhbeLFZfVBmJQGbyKljz9ZtZ0GJdFXx9llAgMBAAECggEAW1uaVYF8niAG/1W/f5HGP8A15sT89RgfXzUc2iLshr8q46TcZg5h86ogJuTTs6RuEp/wMpgk0OHGV0QRcY2o5zHynE52qJqMwlTVwv4ibyZWwlW7ddg/l9S4TFSSgCrnK49SXt1/D8ZITRsHU2C51kFikWHNMy7EYTlmN5soiy+c0MQEqShS/PRcNWj8W2KS4HCBLhtc5w76Y2BjVAboNqGNqQTnKeaFtqFyl8ypE5kIKbnz58ExjjhO6TcAcOVKjdCFWN5kA7Uouv4P5ngd98TZVyKQAbpyZWi4U63O076pHrS+syWmi/IoYFwuK65dBH/rdHDyz+3g+v4D5r68aQKBgQDBKD8wGwHx15V3jDtW9E7wVy6IYqiLuSFj6hlkqAYsGByx6ejgCgWNqSc2puE7F+PtX13keFnANpmSa0JfIeTehLLKHN9Oc836AAxQ60TiNMll8UW1kOrV2bSaL9lHTfjZJC/2b+fEaxkAgnNwkbOrq+TLxUHQmEAxt0srcyNv9wKBgQC599wVa8Q6zeqP2lOTEVCGdeHzNV8bYsp3Cc8k1grF2JnDj3VyFKR9Oldu98bTQmC3/LwDK0olahv6Ss0dy7Prb+jWBHZwl9gGPkHi7ZPtVcoCbCgJSE+RKSnbz+ByZTavN/X6i+9edfkvYFqMCAYqMwiqb3wgHt4CcWfJoj9igwKBgQCu92sNg1lmnXcaHF/gK1uaIA7Zoiy0rFUPsY2g/QbiSFEt5Al7b/iJ0tDfk5jwM3rWmY1umIoMMCk6VYiAri4oVqGxrSemZAYP0J1Xa1YxZcmNW1le18+xOQx8op06Fuo0n7AGlmWmKbEzIfe533GWLxYIcz1j25ZCspsX16shDwKBgGphwYJ3fW9uMApOiJSOyRPCB5lLJLbT0qI5+EdIMi1vdLaMMFEsQdRpNW8DSre7NvzJFPxzHR0+D/ckJyYuSyQZhoY3U1GhazBXGPWpln+kHcU4/cYhmXKeq5VU2z5Va+zcBFhpCGtu7TcO1X1Zcb1eKEznLYhqX/Hh0c9kgwHlAoGBAIpor6iZqqcaGU8lmN3Q8mjdUrqY7PtJwM/Jm1a+tz6Nun7PglyzriNuEZuDaE6soI11O4jHaQrjs9C2D7djnkcrFrZregFK+cejxEbNimdroTcUOBHR8BCr5Zpzj/9EfBfvZwRuLiqd0TRuSO4sqhBgx2a9vbF736tUbXw3c+2C', // 加密方式： **RSA2**  
            'log' => [
                'file' => runtime_path() . '/easy/alipay.log'
            ]
        ]);
        return Pay::alipay(self::$config);
    }

    /**
     * 微信支付
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public static function wechat() {
        $options = AdminConfig::getMore(['system_wechat_appid', 'system_wechat_mchid', 'system_wechat_paysignkey', 'system_wechat_cert_path', 'system_wechat_key_path']);
        self::$config = array_merge(self::$config, [
            'appid' => $options['system_wechat_appid'], // APP APPID
            // 公众号 APPID
            //'app_id' => 'wxb3fxxxxxxxxxxx',
            // 小程序 APPID
            // 'miniapp_id' => 'wxb3fxxxxxxxxxxx',
            'mch_id' => $options['system_wechat_mchid'],
            'key' => $options['system_wechat_paysignkey'],
            'cert_client' => public_path() . $options['system_wechat_cert_path'], //绝对路径
            'cert_key' => public_path() . $options['system_wechat_key_path'], //绝对路径
            'notify_url' => request()->domain() . '/api/easypay/wechat/payment',
            'log' => [
                'file' => runtime_path() . '/easy/wechat.log'
            ]
        ]);
        return Pay::wechat(self::$config);
    }

}
